<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: FinanzasPdf</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">FinanzasPdf</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/lib/finanzas_pdf_rb.html">
                lib/finanzas_pdf.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000011">escribir</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">escribir</span><span class="method-args">(user)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
finanzas_pdf.rb
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
     <span class="ruby-comment cmt"># File lib/finanzas_pdf.rb, line 4</span>
  4: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">escribir</span>(<span class="ruby-identifier">user</span>)
  5:   <span class="ruby-identifier">pdf</span> = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">Writer</span>.<span class="ruby-identifier">new</span>
  6:   
  7:   <span class="ruby-ivar">@ventas</span> = <span class="ruby-constant">Comunicacion</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>,<span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-value str">'type = &quot;Venta&quot;'</span>])
  8:   <span class="ruby-ivar">@ingresos</span> = <span class="ruby-constant">Comunicacion</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>,<span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-value str">'type = &quot;Ingreso&quot;'</span>])
  9:   <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">image</span> <span class="ruby-value str">&quot;./public/images/topbg.jpg&quot;</span>
 10:   <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">'Reporte de Finanzas'</span>,<span class="ruby-identifier">:font_size</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">20</span>,<span class="ruby-identifier">:font_weight</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:bold</span>, <span class="ruby-identifier">:justification</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:center</span>
 11:   <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
 12:   <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">'Fecha: '</span><span class="ruby-operator">+</span><span class="ruby-constant">Date</span>.<span class="ruby-identifier">today</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">:font_size</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">12</span>
 13:   <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">'Hora: '</span><span class="ruby-operator">+</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">hour</span>.<span class="ruby-identifier">to_s</span><span class="ruby-operator">+</span><span class="ruby-value str">':'</span><span class="ruby-operator">+</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">min</span>.<span class="ruby-identifier">to_s</span><span class="ruby-operator">+</span><span class="ruby-value str">':'</span><span class="ruby-operator">+</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">sec</span>.<span class="ruby-identifier">to_s</span>
 14:   <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">'Usuario: '</span><span class="ruby-operator">+</span><span class="ruby-identifier">user</span>.<span class="ruby-identifier">name</span>
 15:   <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
 16:   
 17:   <span class="ruby-identifier">table</span> = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">SimpleTable</span>.<span class="ruby-identifier">new</span>
 18:   
 19:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">heading_color</span> = <span class="ruby-constant">Color</span><span class="ruby-operator">::</span><span class="ruby-constant">RGB</span><span class="ruby-operator">::</span><span class="ruby-constant">White</span>
 20:   
 21:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">shade_headings</span> = <span class="ruby-keyword kw">true</span>
 22:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">shade_heading_color</span> = <span class="ruby-constant">Color</span><span class="ruby-operator">::</span><span class="ruby-constant">RGB</span><span class="ruby-operator">::</span><span class="ruby-constant">Orange</span>
 23:   
 24:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">shade_color</span> = <span class="ruby-constant">Color</span><span class="ruby-operator">::</span><span class="ruby-constant">RGB</span><span class="ruby-operator">::</span><span class="ruby-constant">White</span>
 25:   
 26:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">title</span> = <span class="ruby-value str">&quot;Ventas&quot;</span>
 27:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">title_font_size</span> = <span class="ruby-value">18</span>
 28:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">title_gap</span> = <span class="ruby-value">20</span>
 29: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">column_order</span>.<span class="ruby-identifier">push</span>(<span class="ruby-operator">*</span><span class="ruby-node">%w(Titulo Contacto Fecha Cuenta Usuario Monto)</span>)
 30: 
 31: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;1&quot;</span>] = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">SimpleTable</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;Titulo&quot;</span>)
 32: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;1&quot;</span>].<span class="ruby-identifier">heading</span> = <span class="ruby-value str">&quot;Titulo&quot;</span>
 33: 
 34: 
 35: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;2&quot;</span>] = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">SimpleTable</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;Contacto&quot;</span>)
 36: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;2&quot;</span>].<span class="ruby-identifier">heading</span> = <span class="ruby-value str">&quot;Contacto&quot;</span>
 37: 
 38: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;3&quot;</span>] = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">SimpleTable</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;Fecha&quot;</span>)
 39: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;3&quot;</span>].<span class="ruby-identifier">heading</span> = <span class="ruby-value str">&quot;Fecha&quot;</span>
 40: 
 41: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;4&quot;</span>] = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">SimpleTable</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;Cuenta&quot;</span>)
 42: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;4&quot;</span>].<span class="ruby-identifier">heading</span> = <span class="ruby-value str">&quot;Cuenta&quot;</span>
 43: 
 44: 
 45: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;5&quot;</span>] = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">SimpleTable</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;Usuario&quot;</span>)
 46: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;5&quot;</span>].<span class="ruby-identifier">heading</span> = <span class="ruby-value str">&quot;Usuario&quot;</span>
 47: 
 48: 
 49: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;6&quot;</span>] = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">SimpleTable</span><span class="ruby-operator">::</span><span class="ruby-constant">Column</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;Monto&quot;</span>)
 50: <span class="ruby-identifier">table</span>.<span class="ruby-identifier">columns</span>[<span class="ruby-value str">&quot;6&quot;</span>].<span class="ruby-identifier">heading</span> = <span class="ruby-value str">&quot;Monto&quot;</span>
 51: 
 52: 
 53:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">show_lines</span>    = <span class="ruby-identifier">:all</span>
 54:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">show_headings</span> = <span class="ruby-keyword kw">true</span>
 55:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">orientation</span>   = <span class="ruby-identifier">:center</span>
 56:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">position</span>      = <span class="ruby-identifier">:center</span>
 57: 
 58:         <span class="ruby-identifier">data</span> = <span class="ruby-value str">''</span>
 59:         <span class="ruby-identifier">total</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
 60:         <span class="ruby-identifier">total_ventas</span> = <span class="ruby-value">0</span>
 61:   <span class="ruby-ivar">@ventas</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">com</span><span class="ruby-operator">|</span>
 62:                 <span class="ruby-identifier">monto</span> = <span class="ruby-value">0</span>
 63:                 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">producto</span>
 64:                         <span class="ruby-identifier">monto</span> = <span class="ruby-identifier">com</span>.<span class="ruby-identifier">producto</span>.<span class="ruby-identifier">monto</span>
 65:                         <span class="ruby-identifier">total_ventas</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">producto</span>.<span class="ruby-identifier">monto</span>
 66:                 <span class="ruby-keyword kw">end</span>   
 67:                 <span class="ruby-identifier">data</span> = {<span class="ruby-value str">&quot;Titulo&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">titulo</span>, <span class="ruby-value str">&quot;Contacto&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">contacto</span>.<span class="ruby-identifier">nombre</span>,<span class="ruby-value str">&quot;Cuenta&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">cuenta</span>.<span class="ruby-identifier">razon_social</span>,<span class="ruby-value str">&quot;Fecha&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">fecha</span>.<span class="ruby-identifier">to_s</span>,<span class="ruby-value str">&quot;Usuario&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">user</span>.<span class="ruby-identifier">login</span>, <span class="ruby-value str">&quot;Monto&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">monto</span>.<span class="ruby-identifier">to_s</span>}
 68:                 <span class="ruby-identifier">total</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">data</span>) 
 69:         <span class="ruby-keyword kw">end</span>
 70: 
 71:         <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">total</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword kw">then</span>
 72:         
 73:         <span class="ruby-identifier">table</span>.<span class="ruby-identifier">data</span>.<span class="ruby-identifier">replace</span> <span class="ruby-identifier">total</span>
 74:         <span class="ruby-identifier">table</span>.<span class="ruby-identifier">render_on</span>(<span class="ruby-identifier">pdf</span>)
 75:   
 76:         <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
 77:                 <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">'Total de Ventas: $'</span><span class="ruby-operator">+</span><span class="ruby-identifier">total_ventas</span>.<span class="ruby-identifier">to_s</span>  
 78:         <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
 79:         
 80:         <span class="ruby-keyword kw">else</span>
 81:         
 82:                 <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
 83:                 <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">'No se realizaron ventas'</span>
 84:                 <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
 85:                 
 86:         <span class="ruby-keyword kw">end</span>
 87: 
 88:   
 89:   <span class="ruby-identifier">table</span>.<span class="ruby-identifier">title</span> = <span class="ruby-value str">&quot;Donaciones&quot;</span>
 90:   <span class="ruby-identifier">data</span> = <span class="ruby-value str">''</span>
 91:         <span class="ruby-identifier">total2</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
 92:         <span class="ruby-identifier">total_donaciones</span> = <span class="ruby-value">0</span>
 93:   <span class="ruby-ivar">@ingresos</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">com</span><span class="ruby-operator">|</span>
 94:                 <span class="ruby-identifier">monto</span> = <span class="ruby-value">0</span>
 95:                 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">producto</span>
 96:                         <span class="ruby-identifier">monto</span> = <span class="ruby-identifier">com</span>.<span class="ruby-identifier">producto</span>.<span class="ruby-identifier">monto</span>
 97:                         <span class="ruby-identifier">total_donaciones</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">producto</span>.<span class="ruby-identifier">monto</span>
 98:                 <span class="ruby-keyword kw">end</span>   
 99:                 <span class="ruby-identifier">data</span> = {<span class="ruby-value str">&quot;Titulo&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">titulo</span>, <span class="ruby-value str">&quot;Contacto&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">contacto</span>.<span class="ruby-identifier">nombre</span>,<span class="ruby-value str">&quot;Cuenta&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">cuenta</span>.<span class="ruby-identifier">razon_social</span>, <span class="ruby-value str">&quot;Fecha&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">fecha</span>.<span class="ruby-identifier">to_s</span>,<span class="ruby-value str">&quot;Usuario&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">com</span>.<span class="ruby-identifier">user</span>.<span class="ruby-identifier">login</span>, <span class="ruby-value str">&quot;Monto&quot;</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">monto</span>.<span class="ruby-identifier">to_s</span>}
100:                 <span class="ruby-identifier">total2</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">data</span>) 
101:         <span class="ruby-keyword kw">end</span>
102: 
103:         <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span> <span class="ruby-identifier">total2</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword kw">then</span>
104:   
105:         <span class="ruby-identifier">table</span>.<span class="ruby-identifier">data</span>.<span class="ruby-identifier">replace</span> <span class="ruby-identifier">total2</span>
106:         <span class="ruby-identifier">table</span>.<span class="ruby-identifier">render_on</span>(<span class="ruby-identifier">pdf</span>)
107:   
108:         <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
109:         <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">'Total de Donaciones: $'</span><span class="ruby-operator">+</span><span class="ruby-identifier">total_donaciones</span>.<span class="ruby-identifier">to_s</span>
110:         <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
111:   
112:   <span class="ruby-keyword kw">else</span>
113:   
114:         <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
115:         <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">'No se registraron donaciones'</span>
116:         <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">' '</span>
117:   
118:   <span class="ruby-keyword kw">end</span>
119:   
120:   <span class="ruby-identifier">total</span> = <span class="ruby-identifier">total_ventas</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">total_donaciones</span>
121:   <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">text</span> <span class="ruby-value str">'Total: $'</span><span class="ruby-operator">+</span><span class="ruby-identifier">total</span>.<span class="ruby-identifier">to_s</span>,<span class="ruby-identifier">:font_size</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">18</span>,<span class="ruby-identifier">:font_weight</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:bold</span>  
122:   <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">render</span>
123: <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>